/*
 * calculator.c
 *
 *  Created on: Mar 7, 2013
 *      Author: abrahamsantini
 */
#include "calculator.h"
#include "semaphore.h"
#include "sharedMemory.h"

//#include "process.h"


int init_calc(calculator_t *calc, sharedMemory_t *the_sm){
	calc->sm = the_sm;
	calc->next_instr = 0;
	calc ->num_of_cycles = 0;
	return 0;
}

//int get_value(calculator_t *calc) {
//	semaphore_t temp_sm;
//		temp_sm = calc->sm->calcMutex;
//		int ret = semaphore_up(&temp_sm);
//		calc->my_value = calc->sm->calcValue;
//		return ret;
//}

//int square_value(calculator_t *calc) {
//	calc ->my_value *= calc ->my_value;
//	return 1;
//}
//
//int mod_value(calculator_t *calc) {
//	calc ->my_value = calc -> my_value % 100;
//	return 1;
//}
//
//int return_value(calculator_t *calc) {
//	calc->sm->calcValue = calc->my_value;
//	semaphore_t temp_sm;
//	temp_sm = calc->sm->calcMutex;
//	return semaphore_down(&temp_sm);
//}
//
//int next_calc_instr(calculator_t *calc) {
//	int ret;
//	switch (calc->next_instr) {
//	case 0:
//	ret = get_value(calc);
//	break;
//
//	case 1:
//		ret = square_value(calc);
//		break;
//	case 2:
//		ret = mod_value(calc);
//		break;
//	case 3:
//		ret = return_value(calc);
//	}
//	if(ret>=0) {
//		calc->next_instr = (calc->next_instr + 1) % 4;
//	}
//	return ret;
//}
